package top.blackr.folivora.common.pay.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.blackr.folivora.config.ApplicationProperties;

/**
 * @author BlackR
 */
@Configuration
@AllArgsConstructor
public class WxPayConfiguration {

    private final ApplicationProperties.WxPay wxProperties;

    @Bean
    public Config wxPayConfig() {
        return new RSAAutoCertificateConfig.Builder()
                .merchantId(wxProperties.getMchId())
                .privateKeyFromPath(wxProperties.getWechatPayCertificateUrl())
                .merchantSerialNumber(wxProperties.getMchSerialNo())
                .apiV3Key(wxProperties.getApiV3Key())
                .build();
    }

    @Bean
    public NotificationConfig notificationConfig() {
        return new RSAAutoCertificateConfig.Builder()
                .merchantId(wxProperties.getMchId())
                .privateKeyFromPath(wxProperties.getWechatPayCertificateUrl())
                .merchantSerialNumber(wxProperties.getMchSerialNo())
                .apiV3Key(wxProperties.getApiV3Key())
                .build();
    }
}
